/**
 * Program for turns off\on internet for Android OS
 * 
 * @version 0.9.1
 * @author: Alexander Klimenkov <alex.klimenkov89@gmail.com>
 * 
 */

package android.offnet;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ToggleButton;

public class OffNetActivity extends Activity {

	private Connection con;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		ToggleButton btn = (ToggleButton) findViewById(R.id.btn);
		con = new Connection(OffNetActivity.this);

		if (!con.getConnection()) {
			btn.setChecked(false);
			State.setState(State.OFF);
		} else {
			btn.setChecked(true);
			State.setState(State.ON);
		}
	}

	public void HandlerButton(View target) {
		switch (target.getId()) {
		case R.id.btn:
			ToggleButton btn = (ToggleButton) this.findViewById(R.id.btn);
			if (btn.isChecked()) {
				con.setConnection(State.ON);
				State.setState(State.ON);
			} else {
				con.setConnection(State.OFF);
				State.setState(State.OFF);
			}
			break;

		default:
			break;
		}
	}
}